package router

import (
	"github.com/gin-gonic/gin"
	"self/client/client"
	"self/client/enit"
	"self/common/proto/user"
)

func Registers(c *gin.Context) {
	var data enit.Login
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	login, err := client.Login(c, &user.RegisterReq{
		Username: data.Username,
		Password: data.Password,
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": login,
	})

}
func UserList(c *gin.Context) {
	var data enit.UserList
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	list, err := client.UserList(c, &user.UserListReq{})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": list,
	})
}
